/**
 * gcog - generate code with inlined Groovy code.
 * http://code.google.com/p/gcog/
 * 
 * Copyright 2008, Tobias Hientzsch.
 * 
 * MIT license http://www.opensource.org/licenses/mit-license.php
 * 
 * Original idea and code from Cog code generation tool.
 * http://nedbatchelder.com/code/cog
 *
 * Copyright 2004-2008, Ned Batchelder.
 * 
 */

import static WhiteUtils.*

public class Makefiles{

	static def makefiles(d, basedir='.', raw=false) {
	    """ Create files from the dictionary d, in the directory named by dirpath.
	    """
	    def dirpath = basedir
	    d.each{name, contents ->
	    //for name, contents in d.items():
	        def child = dirpath + "/" + name
	        if(contents instanceof String) {
//	            mode = 'w'
//	            if raw:
//	                mode = 'wb'
	            def f = new FileWriter(new File(child))
//	            if not raw:
	            contents = reindentBlock(contents)
	            f.write(contents)
	            f.close()
	        } else {
//	            if not child.exists():
//	                child.mkdir()
//	            makeFiles(contents, child, raw=raw)
	        }
	    }
	}
	
}
